package ascript.utilities
{
	//#########################
	// Header Includes
	//#########################
	import ascript.components.collision.CollisionBase;
	import ascript.GameObject;
	import Box2D.Collision.b2Manifold;
	import Box2D.Dynamics.b2ContactImpulse;
	import Box2D.Dynamics.b2ContactListener;
	import Box2D.Dynamics.Contacts.b2Contact;
	import flash.utils.getQualifiedSuperclassName;
	
	//#########################
	// Class Declaration
	//#########################
	public class CollisionListener extends b2ContactListener
	{
		//=========================
		// Constructors
		//=========================	
		public function CollisionListener():void
		{
		}
		
		//=========================
		// Members
		//=========================	
		override public function BeginContact( tContact:b2Contact ):void
		{
			if ( tContact.GetFixtureA().GetBody().GetUserData().getComponent( "Collision" ) != null )
			{
				tContact.GetFixtureA().GetBody().GetUserData().getComponent( "Collision" ).handleCollision( tContact.GetFixtureA().GetBody().GetUserData(), tContact.GetFixtureB().GetBody().GetUserData(), tContact.GetFixtureA(), tContact.GetFixtureB(), true );
			}
			if ( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).handleCollision( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), tContact.GetFixtureB(), tContact.GetFixtureA(), true );
			}
		}
		
		override public function EndContact( tContact:b2Contact ):void
		{
			if ( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).handleCollision( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), tContact.GetFixtureA(), tContact.GetFixtureB(), false );
			}
			if ( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).handleCollision( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), tContact.GetFixtureB(), tContact.GetFixtureA(), false );
			}
		}
		
		override public function PreSolve( tContact:b2Contact, tManifold:b2Manifold ):void 
		{
			if ( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).solveCollision( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), tContact.GetFixtureA(), tContact.GetFixtureB(), true );
			}
			if ( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).solveCollision( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), tContact.GetFixtureB(), tContact.GetFixtureA(), true );
			}
		}
		
		override public function PostSolve( tContact:b2Contact, tImpulse:b2ContactImpulse ):void
		{
			if ( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).solveCollision( ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), tContact.GetFixtureA(), tContact.GetFixtureB(), false );
			}
			if ( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) != null )
			{
				( ( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData() ).getComponent( "Collision" ) ).solveCollision( ( ( tContact.GetFixtureB() ).GetBody() ).GetUserData(), ( ( tContact.GetFixtureA() ).GetBody() ).GetUserData(), tContact.GetFixtureB(), tContact.GetFixtureA(), false );
			}
		}
	}
}